package com.woniuxy.yoga.progress.web.controller;


import cn.hutool.core.bean.BeanUtil;
import com.woniuxy.yoga.commons.core.model.Result;
import com.woniuxy.yoga.commons.web.log.YogaLog;
import com.woniuxy.yoga.progress.model.form.CreateTeaCardForm;
import com.woniuxy.yoga.progress.model.param.CreateTeaCardParam;
import com.woniuxy.yoga.progress.service.TeacardService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import javax.validation.constraints.NotNull;

/**
 * <p>
 * 团课流程表 前端控制器
 * </p>
 *
 * @author 韦用文,刘存益,郎腾霄
 * @since 2023年11月28日
 */
@RestController
@RequestMapping("/teacard")
@Api(tags = "团课进度管理")
public class TeacardController {

    @Autowired
    private TeacardService teacardService;

    /**
     * 创建团课进度表
     * @param form 创建团课进度表参数
     * @return String
     */
    @PostMapping("/createTeaCard")
    @ApiOperation("创建团课进度表")
    @YogaLog("创建团课进度表")
    public Result<?> createTeaCard(@RequestBody @Valid CreateTeaCardForm form){
        teacardService.createTeaCard(BeanUtil.toBean(form, CreateTeaCardParam.class));
        return Result.getResult().setMessage("创建团课进度表成功");
    }

    /**
     * 完成团课
     * @param teacardId 团课进度表id
     * @return String
     */
    @GetMapping("/finishTeacard/{teacardId}")
    @ApiOperation("完成团课")
    @YogaLog("完成团课")
    public Result<String> finishTeacard(@PathVariable("teacardId") @Valid @NotNull Integer teacardId){
        teacardService.finishTeacard(teacardId);
        return Result.getResult(String.class).setMessage("操作成功");
    }

}

